package com.example.homework.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.homework.R;
import com.example.homework.adapter.VideoAdapter;
import com.example.homework.bean.VideoItem;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link VideosFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class VideosFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public VideosFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment VideosFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static VideosFragment newInstance(String param1, String param2) {
        VideosFragment fragment = new VideosFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_videos,container,false);
        // Inflate the layout for this fragment
        ViewPager2 viewPager2 = view.findViewById(R.id.videoViewPager);
        List<VideoItem> videoItems = new ArrayList<>();
        VideoItem videoItemOne = new VideoItem();
        videoItemOne.videoURL = "https://sns-video-al.xhscdn.com/stream/79/110/258/01e7d64ed84844d04f037001959d2997fd_258.mp4?sign=7de2b04efd229556afb40799ca27a2ac&t=683745e5";
        videoItemOne.videoTitle = "杨洋";
        videoItemOne.videoSubTitle ="凡人修仙传马上开播！";
        videoItems.add(videoItemOne);
        VideoItem videoItemTwo = new VideoItem();
        videoItemTwo.videoURL = "https://sns-video-hw.xhscdn.com/stream/79/110/258/01e83c43707e107b4f037001972b67a310_258.mp4";
        videoItemTwo.videoTitle = "陈路周";
        videoItemTwo.videoSubTitle = "陷入我们的热恋";
        videoItems.add(videoItemTwo);
        VideoItem videoItemThree = new VideoItem();
        videoItemThree.videoURL = "https://sns-video-hw.xhscdn.com/stream/110/258/01e6c99e5f6e0fb6010370019183941cb0_258.mp4";
        videoItemThree.videoTitle = "螺蛳粉";
        videoItemThree.videoSubTitle = "臭宝螺蛳粉好吃！";
        videoItems.add(videoItemThree);
        VideoItem videoItemFour = new VideoItem();
        videoItemFour.videoURL = "https://sns-video-hw.xhscdn.com/stream/79/110/258/01e831838d66c03d4f03700197016b23a5_258.mp4";
        videoItems.add(videoItemFour);
        viewPager2.setAdapter(new VideoAdapter(videoItems));
        return view;
    }
}